package com.js.rest.bot;

import cn.dev33.satoken.stp.StpUtil;
import com.js.domian.entity.bot.WebsocketEntity;
import com.js.domian.model.AjaxResult;
import com.js.domian.vo.bot.WebsocketVo;
import com.js.service.bot.basics.WebsocketService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.ExecutionException;

@RequestMapping("/bot/websocket")
@RestController
@RequiredArgsConstructor
public class WebsocketRest {
    private final WebsocketService websocketService;

    @PostMapping("/getWebsocketList")
    public AjaxResult getWebsocketList(@RequestBody WebsocketVo vo){
        vo.setCreateBy(StpUtil.getLoginIdAsString());
        return AjaxResult.ok(websocketService.getWebsocketList(vo));
    }

    @PostMapping("/addWebsocket")
    public AjaxResult addWebsocket(@RequestBody WebsocketEntity entity) throws ExecutionException, InterruptedException {
        entity.setCreateBy(StpUtil.getLoginIdAsString());
        websocketService.addWebsocket(entity);
        return AjaxResult.ok();
    }

    @GetMapping("/deleteWebsocket")
    public AjaxResult deleteWebsocket(@RequestParam("id") Integer id){
        websocketService.deleteWebsocket(id);
        return AjaxResult.ok();
    }

    @PostMapping("/connect")
    public AjaxResult connect(@RequestBody WebsocketEntity entity) {
        websocketService.connect(entity);
        return AjaxResult.ok();
    }
}
